package com.example.mk.UI.Navi;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.mk.R;

public class NaviBarView extends FrameLayout implements View.OnClickListener {
    private View.OnClickListener mLeftOnClickListener;
    private ImageButton mBackBtn;
    private TextView mTittleView;

    public NaviBarView(@NonNull Context context) {
        super(context);
        LayoutInflater.from(context).inflate(R.layout.navi_bar_view, this);
        mBackBtn = findViewById(R.id.navi_left);
        mBackBtn.setOnClickListener(this);
        mTittleView = findViewById(R.id.navi_title);
    }

    public NaviBarView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.navi_bar_view, this);
        mBackBtn = findViewById(R.id.navi_left);
        mBackBtn.setOnClickListener(this);
        mTittleView = findViewById(R.id.navi_title);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.navi_left:
                if (mLeftOnClickListener != null) {
                    mLeftOnClickListener.onClick(v);
                }
                break;
        }
    }

    public void hideBackBtn() {
        mBackBtn.setVisibility(View.GONE);
    }

    public void setLeftOnClickListener(View.OnClickListener leftOnClickListener) {
        mLeftOnClickListener = leftOnClickListener;
    }

    public void setTittle(String title){
        mTittleView.setText(title);
    }
}